package org.chengn.level_hard.context2132;

/**
 * @Title: Context2132WA
 * @Author ChengN
 * @Package org.chengn.level_hard.context2132
 * @Date 2023/12/14 23:39
 * @description: 用邮票贴满网格图WA
 */
public class Context2132WA {
    public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) {
        int m = grid.length, n = grid[0].length;
        int[][][] sums = new int[m + 1][n + 1][2];
        for (int i = 1; i <= m + 1; ++i) {
            for (int j = 1; j <= n + 1; ++j) {
                if (i == m + 1 || j == n + 1 || grid[i - 1][j - 1] == 1) {
                    if (i <= m && j <= n) {
                        sums[i][j][0] = sums[i][j][1] = 0;
                    }
                    if (j <= n && sums[i - 1][j][0] > 0 && sums[i - 1][j][0] < stampHeight) return false;
                    if (i <= m && sums[i][j - 1][1] > 0 && sums[i][j - 1][1] < stampWidth) return false;

                } else {
                    sums[i][j][0] = sums[i - 1][j][0] + 1;
                    sums[i][j][1] = sums[i][j - 1][1] + 1;
                }
            }
        }
        return true;

    }
}
